<?php
namespace App\Common\Cla\User\XXX;

use App\Common as com;
use App\Common\Cla\User\XXX\Save as thisSave;

class OfIdOrObj extends com\cla\ClaBase {

	/**
	 * 用户id
	 * @var int
	 */
	private int $xxxId;

	/**
	 * 用户对象
	 * @var self
	 */
	private self $xxxOfIdObj;

	/**
	 * OfIdOrId constructor.
	 * @param self|int $xxxIdOrObj
	 */
	public function __construct( protected self|int $xxxIdOrObj ) {
		parent::__construct();
	}

	/**
	 * @return int|$this
	 */
	public function getXxxIdOrObj(  ):self|int {
		return $this->xxxIdOrObj;
	}

	/**
	 * 获取xxxid
	 * @return int
	 * @throws
	 */
	public function getXxxId(  ):int {
		if( ! isset( $this->xxxId ) ){
			if( $this->xxxIdOrObj instanceof self ){
				$this->xxxId = $this->xxxIdOrObj->getXxxId();
			}else{
				$this->xxxId = $this->xxxIdOrObj;
			}
		}
		//
		return $this->xxxId ;
	}

	/**
	 * 获取xxx对象
	 * @return nameXxx\OfId
	 * @throws
	 */
	public function getXxxOfIdObj(  ):nameXxx\OfId {
		if( ! isset( $this->xxxOfIdObj ) ){
			if( $this->xxxIdOrObj instanceof nameXxx\OfId ){
				$this->xxxOfIdObj = $this->xxxIdOrObj;
			}else{
				$this->xxxOfIdObj = nameXxx\OfId::makeByXxxIdOrObj( $this->getXxxId() );
			}
		}
		return $this->xxxOfIdObj;
	}

	// ===============================
	//
	//
	// 下面为静态方法
	//
	//
	// ===============================

	/**
	 * @param self|int $xxxIdOrObj
	 * @return static
	 */
	public static function makeByXxxIdOrObj( self|int $xxxIdOrObj ):static {
		return self::make( ...func_get_args() );
	}

}
